package com.scau.meetingbook.controller;

import com.alibaba.fastjson.JSONObject;
import com.alipay.api.AlipayApiException;
import com.scau.meetingbook.dto.EnableCancellReservationDTO;
import com.scau.meetingbook.dto.ReservationDTO;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import com.scau.meetingbook.service.RoomReservationsService;
import com.scau.meetingbook.pojo.RoomReservations;
import com.scau.meetingbook.vo.ResultVO;

import java.text.ParseException;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/roomReservations")
public class RoomReservationsController {

    @Autowired
    private RoomReservationsService roomReservationsService;

    /**
     * 创建会议室预约订单
     * 超时订单自动关闭
     * 返回订单ID
     */
    @PostMapping("/createReservation")
    @ApiOperation("创建会议室预约订单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "roomId", value = "会议室ID", required = true, dataType = "Integer"),
            @ApiImplicitParam(name = "UserId", value = "用户ID", required = true, dataType = "Integer"),
            @ApiImplicitParam(name = "date", value = "预约日期 (格式: yyyy-MM-dd)", required = true, dataType = "Date"),
            @ApiImplicitParam(name = "startTime", value = "开始时间 (格式: HH:mm)", required = true, dataType = "String", example = "09:00"),
            @ApiImplicitParam(name = "endTime", value = "结束时间 (格式: HH:mm)", required = true, dataType = "String", paramType = "query", example = "10:00"),
            @ApiImplicitParam(name = "perosonNum", value = "参会人数",required = true,dataType = "Integer")
    })
    public ResultVO createReservation(@RequestBody ReservationDTO reservationDTO){
        return roomReservationsService.createReservation(reservationDTO);
    }

    /**
     * 查询支付总价
     * @param reservationId
     * @return
     */
    @PutMapping("/getTotalPrice")
    @ApiOperation("查询支付总价")
    public ResultVO getTotalPrice(String reservationId){
        return roomReservationsService.getTotalPrice(reservationId);
    }

    /**
     * 支付订单
     * @param reservationId
     * @return
     */
    @PutMapping("/payReservation")
    @ApiOperation("支付订单")
    public String payReservation(String reservationId) throws AlipayApiException {
        return roomReservationsService.payReservation(reservationId);
    }


    /**
     * 获取可取消的订单
     * @return
     */
    @GetMapping("/getEnableCancellReservations")
    @ApiOperation("查询可取消的订单")
    public ResultVO<List<EnableCancellReservationDTO>> getEnableCancellReservations(Integer userId){
        return roomReservationsService.getEnableCancellReservations(userId);
    }


    @PostMapping("/insertRoomReservations")
    public ResultVO insertRoomReservations(@RequestBody RoomReservations roomReservations) throws Exception {
        return roomReservationsService.insertRoomReservations(roomReservations);
    }

    @GetMapping("/getRoomReservationsById")
    public ResultVO<RoomReservations> getRoomReservationsById(Integer id) throws Exception {
        return roomReservationsService.getRoomReservationsById(id);
    }

    @PutMapping("/updateRoomReservationsById")
    public ResultVO updateRoomReservationsById(@RequestBody RoomReservations roomReservations) throws Exception {
        return roomReservationsService.updateRoomReservationsById(roomReservations);
    }

    @DeleteMapping("/deleteRoomReservationsById")
    public ResultVO deleteRoomReservationsById(Integer id) throws Exception {
        return roomReservationsService.deleteRoomReservationsById(id);
    }

    @GetMapping("/getHistoryReservationsByID")
    public ResultVO<List<RoomReservations>> getHistoryReservationsByID(Integer id) {
        return roomReservationsService.getHistoryReservationsByID(id);
    }



}